package com.mall.order.converter;

import com.mall.order.dal.entitys.Order;
import com.mall.order.dal.entitys.OrderItem;
import com.mall.order.dal.entitys.OrderShipping;
import com.mall.order.dto.*;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

import java.util.List;

/**
 *  ciggar
 * create-date: 2019/7/31-上午9:57
 */
@Mapper(componentModel = "spring")
public interface OrderConverter {

    @Mappings({})
    OrderDetailResponse order2res(Order order);

    @Mappings({
            @Mapping(source ="orderId",target = "orderId"),
            @Mapping(source ="payment",target = "payment"),
            @Mapping(source ="paymentType",target = "paymentType"),
            @Mapping(source ="postFee",target = "postFee"),
            @Mapping(source ="status",target = "status"),
            @Mapping(source ="createTime",target = "createTime"),
            @Mapping(source ="updateTime",target = "updateTime"),
            @Mapping(source ="paymentTime",target = "paymentTime"),
            @Mapping(source ="consignTime",target = "consignTime"),
            @Mapping(source ="endTime",target = "endTime"),
            @Mapping(source ="closeTime",target = "closeTime"),
            @Mapping(source ="shippingName",target = "shippingName"),
            @Mapping(source ="shippingCode",target = "shippingCode"),
            @Mapping(source ="userId",target = "userId"),
            @Mapping(source ="buyerMessage",target = "buyerMessage"),
            @Mapping(source ="buyerNick",target = "buyerNick"),
            @Mapping(source ="buyerComment",target = "buyerComment")
    })
    OrderDetailInfo order2detail(Order order);

    @Mappings(
           {
                    @Mapping(source ="id",target = "id"),
                    @Mapping(source ="itemId",target = "itemId"),
                    @Mapping(source ="orderId",target = "orderId"),
                    @Mapping(source = "num",target = "num"),
                    @Mapping(source = "title",   target ="title" ),
                    @Mapping(source = "price",   target ="price" ),
                    @Mapping(source = "totalFee",target ="totalFee" ),
                    @Mapping(source = "picPath", target ="picPath" )
            })
    OrderItemDto item2dto(OrderItem item);

    @Mappings({
            @Mapping(source = "orderId",target = "orderId"),
            @Mapping(source = "receiverName",target = "receiverName"),
            @Mapping(source = "receiverPhone",target = "receiverPhone"),
            @Mapping(source = "receiverMobile",target = "receiverMobile"),
            @Mapping(source = "receiverState",target = "receiverState"),
            @Mapping(source = "receiverCity",target = "receiverCity"),
            @Mapping(source = "receiverDistrict",target = "receiverDistrict"),
            @Mapping(source = "receiverAddress",target = "receiverAddress"),
            @Mapping(source = "receiverZip",target = "receiverZip"),
    })
    OrderShippingDto shipping2dto(OrderShipping shipping);


    List<OrderItemDto> item2dto(List<OrderItem> items);

    @Mappings({})
    OrderItemResponse item2res(OrderItem orderItem);

    @Mappings({})
    OrderDto order2dto(Order order);


}
